#include "student_ext.h"
#include "book_ext.h"
#include <stdio.h>

int main() {
    // --------------------------
    // 测试Student扩展函数
    // --------------------------
    printf("===== 测试Student扩展函数 =====\n");
    Student stu1, stu2;
    Student_init(&stu1, "张三", 18, 75.5f);
    Student_init(&stu2, "李四", 20, 58.0f);

    // 使用EXTEND宏调用扩展函数（显式、易调试）
    EXTEND(Student, &stu1, print_info);  // 打印信息
    printf("张三是否及格：%s\n",
           EXTEND(Student, &stu1, is_passed) ? "是" : "否");

    EXTEND(Student, &stu1, update_score, 82.0f);  // 更新分数
    printf("张三更新后是否及格：%s\n",
           EXTEND(Student, &stu1, is_passed) ? "是" : "否");

    printf("张三是否比李四年长：%s\n",
           EXTEND(Student, &stu1, is_older_than, &stu2) ? "是" : "否");

    // --------------------------
    // 测试Book扩展函数
    // --------------------------
    printf("\n===== 测试Book扩展函数 =====\n");
    Book book;
    Book_init(&book, "C语言编程", "张三", 59.9f, 320);

    // 使用EXTEND宏调用扩展函数
    EXTEND(Book, &book, print_info);  // 打印信息
    printf("是否为厚书（>=300页）：%s\n",
           EXTEND(Book, &book, is_thick, 300) ? "是" : "否");

    float price = EXTEND(Book, &book, get_discounted_price, 0.2f, true);
    printf("折扣后价格：%.2f元\n", price);

    // --------------------------
    // 测试边界情况
    // --------------------------
    printf("\n===== 测试边界情况 =====\n");
    printf("李四是否及格：%s\n",
           EXTEND(Student, &stu2, is_passed) ? "是" : "否");

    float extreme_price = EXTEND(Book, &book, get_discounted_price, 0.9f, false);
    printf("极端折扣后价格：%.2f元\n", extreme_price);

    return 0;
}
